﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 策略模式
{
    abstract class Strategy
    {
        public abstract void absStrategy();
    }

    interface IStrategy
    {
        public void Strategy();
    }

    class ComA : Strategy, IStrategy
    {
        public override void absStrategy()
        {
            Console.WriteLine("ComA---absStrategy");
        }

        public void Strategy()
        {
            Console.WriteLine("ComA---Strategy");
        }
    }

    class ComB : Strategy, IStrategy
    {
        public override void absStrategy()
        {
            Console.WriteLine("ComB---absStrategy");
        }

        public void Strategy()
        {
            Console.WriteLine("ComB---Strategy");
        }
    }

    class ComC : Strategy, IStrategy
    {
        public override void absStrategy()
        {
            Console.WriteLine("ComC---absStrategy");
        }

        public void Strategy()
        {
            Console.WriteLine("ComC---Strategy");
        }
    }

    /// <summary>
    /// 抽象上下文
    /// </summary>
    class Context
    {
        Strategy strategy;
       
        public Context(Strategy _strategy)
        {
            this.strategy = _strategy;
        }
        public void absContextInterface()
        {
            strategy.absStrategy();
        }
    }

    /// <summary>
    /// 接口上下文
    /// </summary>
    class IContext
    {
        IStrategy Istrategy;
        public IContext(IStrategy _strategy)
        {
            this.Istrategy = _strategy;
        }
        public void ContextInterface()
        {
            Istrategy.Strategy();
        }
    }



}
